package com.cwj;

import java.util.Arrays;

public class Floyd {

    public void solution(int[][] edges, int n) {
        int[][] distance = new int[n][n];
        int max = 0x7fffffff;
        for (int[] dis : distance) {
            Arrays.fill(dis, max);
        }
        for (int[] edge : edges) {
            distance[edge[0]][edge[1]] = edge[2];
            distance[edge[1]][edge[0]] = edge[2];
        }
        for (int i = 0; i < n; i++) {
            distance[i][i] = 0;
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    if (distance[j][i] != max && distance[i][k] != max) {
                        distance[j][k] = Math.min(distance[j][k], distance[j][i] + distance[i][k]);
                    }
                }
            }
        }

    }
}
